package br.com.equus.DAO.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import br.com.equus.DAO.AgendaDAO;
import br.com.equus.entidade.AvaliacaoAnimal;
import br.com.equus.entidade.ItemEntrada;
import br.com.equus.entidade.ManejoAnimal;
import br.com.equus.entidade.MedicaoAnimal;

@Repository(value = "agendaDAO")
public class AgendaDAOImpl extends HibernateDaoSupport implements AgendaDAO {

	@Autowired(required = true)
	public void setFactory(SessionFactory factory) {
		super.setSessionFactory(factory);
	}

	@Override
	public List<ManejoAnimal> carregarListaManejo(Date dataInicial, Date dataFinal) throws Exception {
		Criteria c = getSession().createCriteria(ManejoAnimal.class);

		c.add(Restrictions.and(Restrictions.ge("dtInicio", dataInicial), Restrictions.le("dtFim", dataFinal)));

		return c.list();
	}

	@Override
	public List<AvaliacaoAnimal> carregarListaAvaliacao(Date start, Date end) throws Exception {
		Criteria c = getSession().createCriteria(AvaliacaoAnimal.class);

		c.add(Restrictions.between("dtCadastro", start, end));

		return c.list();
	}

	@Override
	public List<MedicaoAnimal> carregarListaMedicao(Date start, Date end) throws Exception {
		Criteria c = getSession().createCriteria(MedicaoAnimal.class);

		c.add(Restrictions.between("dtCadastro", start, end));

		return c.list();
	}

	@Override
	public List<ItemEntrada> carregarListaItem(Date start, Date end) {
		Criteria c = getSession().createCriteria(ItemEntrada.class);

		c.add(Restrictions.between("dtValidade", start, end));

		return c.list();
	}
}
